package com.xmut.mall.member.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xmut.mall.member.dto.MemberEvaluationDTO;
import com.xmut.mall.member.myenum.SwitchEnum;
import com.xmut.mall.member.utils.StringUtils;
import com.xmut.mall.member.vo.OrderEntityVo;
import com.xmut.mall.member.vo.SkuInfoEntityVo;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 会员商品评价
 *
 * @author Bulbasaur
 * @since 2020-02-25 14:10:16
 */
@Data
@TableName("li_member_evaluation")
@NoArgsConstructor
public class MemberEvaluationEntity  {

    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.ID_WORKER)
    private Long id;

    private Long memberId;

    @NotNull
    private Long storeId;

    @NotNull
    private String storeName;

    @NotNull
    private Long goodsId;

    @NotNull
    private Long skuId;

    @NotNull
    private String memberName;

    @NotNull
    private String memberProfile;

    @NotNull
    private String goodsName;

    @NotNull
    private String goodsImage;

    @NotNull
    private String orderNo;

    @NotNull
    private String grade;

    @NotNull
    private String content;

    private String images;

    @NotNull
    private String status;

    private String reply;

    private String replyImage;

    private Boolean haveImage;

    private Boolean haveReplyImage;

    private boolean replyStatus;

    private Integer deliveryScore;

    private Integer serviceScore;

    private Integer descriptionScore;

    private Date createTime;


    public MemberEvaluationEntity(MemberEvaluationDTO memberEvaluationDTO, SkuInfoEntityVo goodsSku, MemberEntity member, OrderEntityVo order) {
        //复制评价信息
        BeanUtils.copyProperties(memberEvaluationDTO, this);
        //设置会员
        this.memberId = member.getId();
        //会员名称
        this.memberName = member.getUsername();
        //设置会员头像
        this.memberProfile = member.getHeader();
        //商品名称
        this.goodsName = goodsSku.getSkuName();
        //商品图片
        this.goodsImage = goodsSku.getSkuDefaultImg();
        //设置店铺ID
        this.storeId = order.getStoreId();
        //设置店铺名称
        this.storeName = order.getStoreName();
        //设置订单编号
        this.orderNo = order.getSn();
        //是否包含图片
        this.haveImage = StringUtils.isNotEmpty(memberEvaluationDTO.getImages());
        //默认开启评价
        this.status = SwitchEnum.OPEN.name();
    }
}